/**
 * 郭楠project
 * com.gn.controller
 * XcxMarketCotroller.java
 * 创建人:TonyGuo 
 * 时间：2017年1月10日-下午9:19:40 
 * 2017Tm公司-版权所有
 */
package com.gn.controller;

import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.gn.entity.XcxMarket;
import com.gn.service.XcxMarketService;

/**
 * 小程序
 * XcxMarketCotroller
 * 创建人:TonyGuo
 * 时间：2017年1月10日-下午9:19:40 
 * @version 1.0.0
 * 
 */
@RestController
@RequestMapping("/xcx")
public class XcxMarketCotroller {
	private static Logger logger = LoggerFactory.getLogger(XcxMarketCotroller.class);
	@Resource
	XcxMarketService xcxMarketService;
	
	/**
	 * 【保存】
	 * @param xcxMarket
	 * @return true
	 * */
	@RequestMapping(value="/save",method=RequestMethod.GET)
	public boolean save(XcxMarket xcxMarket){
		try {
			String appName = new String(xcxMarket.getAppName().getBytes("iso-8859-1"),"utf-8");
			String category = new String(xcxMarket.getCategory().getBytes("iso-8859-1"),"utf-8");
			String introduce = new String(xcxMarket.getIntroduce().getBytes("iso-8859-1"),"utf-8");
			xcxMarket.setAppName(appName);
			xcxMarket.setCategory(category);
			xcxMarket.setIntroduce(introduce);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		logger.info("xcx toString:{}",xcxMarket.toString());
		xcxMarketService.save(xcxMarket);
		return true;
	};
	
	/**
	 * 【删除】
	 * @param id
	 * @return boolean
	 * @since  1.0.0
	 */
	@RequestMapping(value="/delete/{id}",method=RequestMethod.GET)
	public boolean delete(@PathVariable("id") String id){
		if(!"".equals(id)){
			 xcxMarketService.delete(id);
			 return true; 
		}else
			return false;
	};
	
	/**
	 * 【更新】
	 * @param xcxMarket
	 * @return boolean
	 * @exception 
	 * @since  1.0.0
	 */
	public boolean update(XcxMarket xcxMarket){
		
		return false;
	};
	
	/**
	 * 【查询单个小程序】
	 * @param id
	 * @return XcxMarket
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	public XcxMarket findById(@PathVariable("id") String id){
		if(!"".equals(id))
			return xcxMarketService.findById(id);
		else
			return null;
		
	};
	
	/**
	 * 【查询所有小程序】
	 * @return List<XcxMarket>
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value="/findAll",method=RequestMethod.GET)
	public List<XcxMarket> findAll(){
		return xcxMarketService.findAll();
	};
	
	/**
	 * 【获取小程序总数】
	 * @param id
	 */
	@RequestMapping(value="/count.get",method=RequestMethod.GET)
	public long count(){
		 return xcxMarketService.count();
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
